package String;

/**
 *
 *
 */

public class StringDemo {

    public static void main(String[] args){
        String s1="123abc";
        String s2="123abc";
        System.out.println("s1:"+s1);
        System.out.println("s2:"+s2);
        System.out.println(s1==s2);
        String s3="123abc";
        System.out.println("s3="+s3);
        System.out.println(s1==s3);
        //new一定创建新对象，并不推荐这样的做法
        String s4 =new String("123abc");
        System.out.println("s4:"+s4);
        System.out.println(s1==s4);

        /**
         *
         *
         *
         */

        String s5="123"+"abc";
        System.out.println("s5="+s5);
        System.out.println(s1==s5); //true

        String s ="123";
        String s6 =s+"abc"; //这里不会触发预计算特性
        System.out.println("s6="+s6);
        System.out.println(s1==s6);

        s1=s2+"!";//修改内容就会创建新对象
        System.out.println("s1"+s1);//123abc!
        System.out.println("s2"+s2);
        System.out.println(s1==s2);//地址不同了
    }
}
